home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / DRAFT.PY < prev    next >
Encoding:
Python Source  |  1999-08-11  |  8.5 KB  |  236 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64. import Globals, AccessControl.User
  65. from Globals import Persistent
  66. from Acquisition import Implicit
  67. from OFS import SimpleItem
  68. from string import rfind
  69.  
  70. manage_addPrincipiaDraftForm=Globals.HTMLFile('draftAdd',globals())
  71. def manage_addPrincipiaDraft(self, id, baseid, PATH_INFO, REQUEST=None):
  72.     "Add a draft object"
  73.     self._setObject(id, Draft(id, baseid, PATH_INFO))
  74.     if REQUEST is not None: return self.manage_main(self,REQUEST)
  75.  
  76. class Draft(Persistent, Implicit, SimpleItem.Item):
  77.     "Daft objects"
  78.     _refid=''
  79.     _version='/version'
  80.     meta_type='Zope Draft'
  81.  
  82.     __ac_permissions__=(
  83.         ('Approve draft changes',
  84.          ('manage_approve__draft__',
  85.           'manage_Save__draft__','manage_Discard__draft__')
  86.          ),
  87.     )
  88.  
  89.     def __init__(self, id, baseid, PATH_INFO):
  90.         self.id=id
  91.         self._refid=baseid
  92.         version=PATH_INFO
  93.         l=rfind(version,'/')
  94.         if l >= 0: version=version[:l]
  95.         self._version="%s/%s" % (version, id)
  96.         self.users__draft__=uf=AccessControl.User.UserFolder()
  97.         self.__allow_groups__=uf
  98.     
  99.     def icon(self):
  100.         try: return getattr(self.aq_parent.aq_base,self._refid).icon
  101.         except: return 'p_/broken'
  102.  
  103.     def manage_options(self):
  104.         try: return getattr(self.aq_parent.aq_base,self._refid).manage_options
  105.         except: return ()
  106.  
  107.     def title(self):
  108.         return 'draft of '+self._refid
  109.  
  110.     def title_and_id(self):
  111.         nonempty=self.nonempty()
  112.         if nonempty:
  113.             return ('draft of %s (%s)'
  114.                     '</a> <a href="%s/users__draft__/manage_main">[Users]'
  115.                     '</a> <a href="%s/manage_approve__draft__">[Approve]'
  116.                     % (self._refid, self.id,
  117.                        self.id,
  118.                        self.id,
  119.                        ))
  120.         else:
  121.             return ('draft of %s (%s)'
  122.                     '</a> <a href="%s/users__draft__/manage_main">[Users]'
  123.                     % (self._refid, self.id,
  124.                        self.id,
  125.                        ))
  126.  
  127.     def __bobo_traverse__(self, REQUEST, name):
  128.         if name[-9:]=='__draft__': return getattr(self, name)
  129.  
  130.         
  131.         try: db=self._p_jar.db()
  132.         except:
  133.             # BoboPOS 2
  134.             jar=Globals.VersionBase[self._version].jar
  135.         else:
  136.             # ZODB 3
  137.             jar=db.open(self._version)
  138.             cleanup=Cleanup()
  139.             cleanup.__del__=jar.close
  140.             REQUEST[Cleanup]=cleanup
  141.             
  142.             
  143.         dself=getdraft(self, jar)
  144.         
  145.         ref=getattr(dself.aq_parent.aq_base,dself._refid).aq_base.__of__(dself)
  146.         if hasattr(ref, name): return dself, ref, getattr(ref, name)
  147.         return getattr(self, name)
  148.     
  149.     def nonempty(self):        
  150.         try: db=self._p_jar.db()
  151.         except:
  152.             # BoboPOS 2
  153.             return Globals.VersionBase[self._version].nonempty()
  154.         else:
  155.             # ZODB 3
  156.             return not db.versionEmpty(self._version)
  157.  
  158.     manage_approve__draft__=Globals.HTMLFile('draftApprove', globals())
  159.  
  160.     def manage_Save__draft__(self, remark, REQUEST=None):
  161.         """Make version changes permanent"""
  162.         try: db=self._p_jar.db()
  163.         except:
  164.             # BoboPOS 2
  165.             Globals.VersionBase[self._version].commit(remark)
  166.         else:
  167.             # ZODB 3
  168.             s=self._version
  169.             d=self._p_jar.getVersion()
  170.             if d==s: d=''
  171.             db.commitVersion(s, d)
  172.             
  173.         if REQUEST:
  174.             REQUEST['RESPONSE'].redirect(REQUEST['URL2']+'/manage_main')
  175.  
  176.     def manage_Discard__draft__(self, REQUEST=None):
  177.         'Discard changes made during the version'
  178.         try: db=self._p_jar.db()
  179.         except:
  180.             # BoboPOS 2
  181.             Globals.VersionBase[self._version].abort()
  182.         else:
  183.             # ZODB 3
  184.             db.abortVersion(self._version)
  185.  
  186.         if REQUEST:
  187.             REQUEST['RESPONSE'].redirect(REQUEST['URL2']+'/manage_main')
  188.  
  189.     def manage_afterClone(self, item):
  190.         self._version=''
  191.  
  192.     def manage_afterAdd(self, item, container):
  193.         if not self._version:
  194.             self._version=self.absolute_url(1)
  195.  
  196.     def manage_beforeDelete(self, item, container):        
  197.         if self.nonempty():
  198.             raise 'Version Error', (
  199.                 'Attempt to %sdelete a non-empty version.<p>'
  200.                 ((self is not item) and 'indirectly ' or ''))
  201.  
  202. Globals.default__class_init__(Draft)
  203.  
  204. def getdraft(ob, jar):
  205.  
  206.     if hasattr(ob,'aq_parent'):
  207.         return getdraft(ob.aq_self, jar).__of__(getdraft(ob.aq_parent, jar))
  208.  
  209.     if hasattr(ob,'_p_oid'): ob=jar[ob._p_oid]
  210.  
  211.     return ob
  212.  
  213.  
  214. class Cleanup: pass
  215.